//
// Created by Tan Ke on 2024/1/20.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int removeElement(int* nums, int numsSize, int val)
{
    int removeCnt = 0;

    for (int i = numsSize - 1; i >= 0; i --) {
        if (nums[i] == val) {
            if (i != numsSize - 1) {
                for (int j = i + 1; j < numsSize - removeCnt; j++) {
                    nums[j - 1] = nums[j];
                }
            }
            removeCnt += 1;
        }
#if 0
        for (int m = 0; m < numsSize - removeCnt; m ++) {
            printf("%d ", nums[m]);
        }
        printf("\n");
#endif
    }
    return numsSize - removeCnt;
}


int main(void)
{
    int nums1[4] = {3, 2, 2, 3};
    printf("%d\n", removeElement(nums1, 4, 3));

    int nums2[8] = {0, 1, 2, 2, 3, 0, 4, 2};
    printf("%d\n", removeElement(nums2, 8, 2));

    return 0;
}